package com.example.boot.modules.auth.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.boot.modules.system.entity.User;
import com.example.boot.modules.system.service.IUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @author 王令
 * @since 2022/7/29 18:07
 */
@Service
@RequiredArgsConstructor
public class ExampleUserDetailsService implements ExampleUserInfoService, UserDetailsService {

    private final IUserService service;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = service.getOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, username));
        return getUserDetailsInfo(service.findUserInfoByUser(user));
    }
}
